﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 信息文档接收对象 数据类
    /// </summary>
    public class DocRecObject
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DocRecObject()
        {
        }
        /// <summary>
        /// 从视图中根据公司编号和信息编号获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-08-16</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docId">信息编号</param>
        /// <returns></returns>
        public DataSet GetListByView(string entityNo, decimal docId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM v_docRecObject ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId=@FDocId ");

            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Decimal),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = docId;
            parameters[1].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-08-16</date>
        /// </summary>
        public Model.DocRecObject DataRowToModel(DataRow row)
        {
            Model.DocRecObject model = new Model.DocRecObject();
            if (row != null)
            {
                if (row["FDocRecID"] != null && row["FDocRecID"].ToString() != "")
                {
                    model.FDocRecID = decimal.Parse(row["FDocRecID"].ToString());
                }
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FWorkGrpNo"] != null)
                {
                    model.FWorkGrpNo = row["FWorkGrpNo"].ToString();
                }
                if (row.Table.Columns.Contains("FEmpName"))
                {
                    model.FEmpName = row["FEmpName"].ToString();
                }
            }
            return model;
        }
    }
}
